package org.durandj.ystream.client.network.packetHandlers;

import javax.swing.JOptionPane;

import org.durandj.ystream.client.YStreamClient;
import org.durandj.ystream.client.message.Message;
import org.durandj.ystream.client.message.MessageID;
import org.durandj.ystream.client.network.Packet;
import org.durandj.ystream.client.network.PacketHandler;

/**
 * This packet handler handles the disconnect packet. The disconnect packet
 * is sent when the server disconnects the client for whatever reason.
 * 
 * @author durandj
 * @version 1.0
 *
 */
public class ClientDisconnectPacketHandler extends PacketHandler
{
	/**
	 * Creates a packet handler for the client disconnect packet.
	 */
	public ClientDisconnectPacketHandler()
	{
		// All the work that really needs to be done is that the super class sets up everything.
		super();
	}
	
	/* (non-Javadoc)
	 * @see org.durandj.ystream.client.network.PacketHandler#handlePacket(org.durandj.ystream.client.network.Packet)
	 */
	@Override
	protected void handlePacket(Packet packet)
	{
		if(packet == null)
			throw new NullPointerException("Must give a valid packet.");
		
		JOptionPane.showMessageDialog(YStreamClient.getClient().getWindow(), "You have been disconnected from the server.");
		YStreamClient.getClient().queueMessage(new Message(Message.Priority.MEDIUM, MessageID.DISCONNECT, this));
	}
}
